import { HttpClient } from '@angular/common/http';
import { Component, OnInit } from '@angular/core';
import { ActivatedRoute } from '@angular/router';
import { Result } from 'src/app/common/bean/result-bean';
import { ArticleVo } from '../../vo/article-vo';
import { DialogService } from 'ngx-metro';
import { Location } from '@angular/common';

@Component({
    selector: 'app-article-page',
    templateUrl: './article-page.component.html',
    styleUrls: ['./article-page.component.scss'],
    standalone: false
})
export class ArticlePageComponent implements OnInit {
  articleId: string;

  articleVo: ArticleVo;

  loading: boolean = true;

  constructor(private route: ActivatedRoute, private http: HttpClient,  private dialogService: DialogService, private location: Location) {}

  ngOnInit(): void {
    this.articleId = this.route.snapshot.paramMap.get('articleId');
    this.getArticle();
  }

  getArticle() {
    this.http
      .get<Result<ArticleVo>>(
        '/article/getArticle?articleId=' + this.articleId
      )
      .subscribe((result) => {
        if(result.success){
          this.articleVo = result.data;
          this.loading=false;
        }else{
          this.loading=false;
          this.dialogService.confirm("Article Not Found", result.message).subscribe((_)=>{
            this.location.back();
          });
          
          
        }

      });
  }
}
